<?php

namespace App\Http\Middleware\CallingCards;

use App\Service\OpenShop\User\RmsUserService;
use Closure;
use Illuminate\Http\Request;

class RmsAuth
{
    public static $userId = 0;

    /**
     * 验证RMS网页是否登录
     * @param Request $request
     * @param Closure $next
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $userInfo = RmsUserService::getAuthUserInfo($request->headers->all());
        $id       = self::$userId = $userInfo['data']['id'] ?? 0;
        if ($id) {
            return $next($request);
        }
        return response()->json(['code' => 401, 'msg' => '尚未登录']);
    }
}
